
MatchCtrl = {};
local this = MatchCtrl;

local Match;
local num = 0;
local name;
--构建函数--
function MatchCtrl.New()
	logWarn("MatchCtrl.New--->>");
	this.ImgObjs = {};
	name = "Match";
	return this;
end

function MatchCtrl.Awake()
	logWarn("MatchCtrl.Awake--->>");
	panelMgr:CreatePanel(name, this.OnCreate);
end

--启动事件--
function MatchCtrl.OnCreate(obj)
	num = 0;
	Game.UpdateCurrentPanel(name);
	Match = obj:GetComponent('LuaBehaviour');
	Match:AddClick(MatchPanel.ReadyBtn, this.ReadyBtnOnClick);
	this.UpdateMacthMsg();
	logWarn("Start lua--->>"..obj.name);
end
--点击时间--
function MatchCtrl.ReadyBtnOnClick(go)
	--logWarn(#this.ImgObjs);
	--this.ImgObjs[go.name]:SetActive(false);
	--go:GetComponent('Button').interactable = false;
	--Match:RemoveClick(MatchPanel.ReadyBtn);

	TcpSendMgr:SendReady();
	
end


function MatchCtrl.SetPlayerReadyState(userid)
	logError(userid.."---".. NetData:GetUserId());
	if userid == NetData:GetUserId() then
		logError("====================");
		MatchPanel.ReadyBtn:GetComponent('Button').interactable = false;
	end
	num = num+1;
	
	this.ImgObjs[userid]:SetActive(false);

	if num == #MatchPanel.ImgTable then
		
		Game.CreatePanel(CtrlNames.GameLoading);
	end
end

--更新匹配列表--
function MatchCtrl.UpdateMacthMsg()
	local playerList = NetData:GetPlayerList();
	local Text ;
	for i = 0,playerList.Length -1 do
		MatchPanel.ImgTable[i+1].name = tostring(playerList[i].userid);
		Text = MatchPanel.ImgTable[i+1].transform:Find("Text"):GetComponent('Text');
		MatchPanel.ImgTable[i+1].color = ColorSwitch[playerList[i].heroid];
		Text.text = playerList[i].username;
		this.ImgObjs[playerList[i].userid] = MatchPanel.ImgTable[i+1].transform:Find("Image").gameObject;

		if playerList[i].userid == NetData:GetUserId() then
			Text.color = ColorSwitch.nameColor;
		end
	end
end

